<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: aquamarine;
           margin: 10px; /* 外边距 */
           display: inline-block;
        }
     </style>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <button onclick="changeColor()">点击按钮进行奇数变色</button>
    <script>
        function changeColor(){
            var ele =document.getElementsByTagName("div");
            console.log(ele)
            for (var indedx=0;index < ele.length;index++){
                if (index%2 ==1){
                    ele[index].setAttribute("style","background-color:#40E0D0");
                }else{
                    ele[index].setAttribute("style","background-color:#CCC");
                }
            }
        }
        
    </script>
</body>
</html>